package sen.queryUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 表单域封装类，目的是实现where条件的关系符可配置
 * 【用法】：
 * ## 要传到后台的表单名=条件关系符#真正表单名。
 * ## 如果条件关系符是SCOPE则表单值以逗号分隔。
 */
public class Conditional implements Cond {

	public final static int GT = 0;//大于
	public final static int LT = 1;//小于
	public final static int EQ = 2;//等于
	public final static int START = 3;//以某开头
	public final static int END = 4;//结尾
	public final static int DIM = 5;//模糊
	public final static int SCOPE = 6;//范围
	public final static int GT_EQ = 7;//大于等于
	public final static int LT_EQ = 8;//小于等于
	public final static int NO_EQ = 9;//不等于
	public final static int L_DIM = 10;//左模糊
	public final static int R_DIM = 11;//右模糊
	public final static int ONE_OF_THEM = 12;//它们其中一个
	
	public final static String GT_ = "GT";//大于
	public final static String LT_ = "LT";//小于
	public final static String EQ_ = "EQ";//等于
	public final static String START_ = "START";//以某开头
	public final static String END_ = "END";//结尾
	public final static String DIM_ = "DIM";//模糊
	public final static String L_DIM_ = "L_DIM";//左模糊
	public final static String R_DIM_ = "R_DIM";//右模糊
	public final static String SCOPE_ = "SCOPE";//范围
	public final static String GT_EQ_ = "GT_EQ";//大于等于
	public final static String LT_EQ_ = "LT_EQ";//小于等于
	public final static String NO_EQ_ = "NO_EQ";//不等于
	public final static String ONE_OF_THEM_ = "ONE_OF_THEM";//它们其中一个
	
	public static Map<String, Integer> keyValue = new HashMap<String, Integer>();
	static {
		keyValue.put(GT_, GT);
		keyValue.put(LT_, LT);
		keyValue.put(EQ_, EQ);
		keyValue.put(START_, START);
		keyValue.put(END_, END);
		keyValue.put(DIM_, DIM);
		keyValue.put(SCOPE_, SCOPE);
		keyValue.put(GT_EQ_, GT_EQ);
		keyValue.put(LT_EQ_, LT_EQ);
		keyValue.put(NO_EQ_, NO_EQ);
	}
	
	public final static String SCOPE_SEPARATE = ",";//范围值的分隔符
	
	private String name;
	private String value;
	private int relator = 2;

	public Conditional() {
	}
	public Conditional(String name, String value, int relator) {
		super();
		this.name = name;
		this.value = value;
		this.relator = relator;
	}
	public Conditional(String name, String value) {
		super();
		this.name = name;
		this.value = value;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public int getRelator() {
		return relator;
	}
	public void setRelator(int relator) {
		this.relator = relator;
	}
	public static int getRelatorValue(String relator) {
		return keyValue.get(relator);
	}
}